//
//  TableViewModel.m
//  MVVMLearn
//
//  Created by 李旭阳[产品技术中心] on 2020/6/2.
//  Copyright © 2020 李旭阳[产品技术中心]. All rights reserved.
//

#import "TableViewModel.h"
#import "CustomModel.h"
#import "HttpTool.h"

@interface TableViewModel()
@property (strong, nonatomic) NSArray *photoModelArray;
@end


@implementation TableViewModel

- (instancetype)init{
    self = [super init];

    if (self) {
        
    }
    return self;
}

#pragma mark -

- (void)headerRefreshRequestWithCallback:(callback)callback{
                
                 NSString *url = @"photos";

                [HttpTool getWithPath:url params:nil hudView:nil success:^(NSArray *JSONDic) {
                         
                    NSMutableArray *photoModels=[NSMutableArray array];

                    self.photoModelArray = JSONDic;
                        
                    for (NSDictionary *dic in self.photoModelArray) {
                            CustomModel *model=[[CustomModel alloc] init];
                            model.title=[dic objectForKey:@"title"];
                            model.albumId = [dic objectForKey:@"albumId"];
                            model.thumbnailUrl = [dic objectForKey:@"thumbnailUrl"];
                            [photoModels addObject:model];
                    }

                    callback(photoModels);
                        
                    } failure:^(NSError *error) {
                        
                        NSLog(@"%ld",error.code);

                }];
         
}


@end
